from __future__ import annotations

import os
import tempfile
from importlib.resources import files


def main() -> None:
    try:
        from streamlit.web.bootstrap import run as st_run
    except Exception as e:
        raise SystemExit("缺少依赖：请先安装 Streamlit。")

    # 读取包内 app.py，写入临时目录后以文件形式启动
    app_text = files("gssgca.ui").joinpath("app.py").read_text(encoding="utf-8")
    with tempfile.TemporaryDirectory() as tmp:
        app_path = os.path.join(tmp, "app.py")
        with open(app_path, "w", encoding="utf-8") as f:
            f.write(app_text)
        # 启动 Streamlit 应用
        st_run(app_path, command_line="streamlit run")


if __name__ == "__main__":
    main()


